<template>
	<view class="law-regulation">
		<common-navbar title="法律法规" />
		<view class="top-charge-bar">
			<view class="charge-info">
				<view class="charge-icon">
					{{chargename.charAt(0)}}
				</view>
				<view class="charge-name">
					{{chargename}}
				</view>
			</view>

			<view class="law-total">
				法律法规({{total}})
			</view>
		</view>
		<scroll-view scroll-y class="scroll-view" @scrolltolower="scrolltolower">
			<view class="law-item" v-for="item in lawList" :key="item.id">
				<view class="law-name">
					{{item.section}}
				</view>
				<!-- 				<view class="law-info">
					<view class="court-name">
						主席令第83号
					</view>
					<view class="effective-date">
					 1997.10.01实施
					</view>
				</view> -->
				<view class="law-content">
					{{item.content}}
				</view>
			</view>
			<u-loadmore :status="status" />
		</scroll-view>
		<vipPopup ref="vipPopup"/>
	</view>
</template>

<script>
	import vipPopup from "../components/vip-popup/vipPopup.vue";
	export default {
		components:{
			vipPopup,
		},
		data() {
			return {
				chargename: '',
				total: 0,
				pageNum: 1,
				pageSize: 10,
				status: 'loadmore',
				lawList: [],
				type:1,
				detailId:'',
			}
		},
		async onLoad(options) {
			console.log(options)
			this.chargename = decodeURIComponent(options.chargename);
			this.type = options.type;
			this.detailId = options.id;
			await this.$loginStatus;
			this.getLawList();
		},
		methods: {
			async getLawList() {
				if (this.status == 'loading' || this.status == 'nomore') {
					return
				}
				this.status = 'loading';
				let options;
				let restUrl;
				try {
					restUrl = this.$restUrl.getLawRegListByChargeId
					if(this.type == 1){
						options = {
							charge_id: this.detailId,
							page: this.pageNum,
							page_num: this.pageSize,
						}
					}else{
						restUrl = this.$restUrl.getLawRegListByChapterId
						options = {
							chapter_id: this.detailId,
							page: this.pageNum,
							page_num: this.pageSize,
						}
					}
					const {
						data,
						total
					} = (await this.$u.post(restUrl,options)).data
					this.total = total;
					this.lawList.push(...data);
					if (this.lawList.length >= total) {
						this.status = 'nomore';
					} else {
						this.status = 'loadmore';
						this.pageNum++;
					}
				} catch (e) {
					if (e.status_code == 404) {
						this.$refs.vipPopup.show();
					}
					return
				}

			},
			scrolltolower() {
				console.log('scrolltolower')
				this.getLawList();
			}
		}
	}
</script>

<style scoped lang="scss">
	@import "./lawRegulation.scss"
</style>
